﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HappyTemplate
{
	public class TemplateHelp
	{
		public static bool IsTrue(object someValue)
		{
			bool retval = false;

			if (someValue != null)
			{
				if(someValue.GetType() == typeof(bool))
					retval = (bool) someValue;

				else if(someValue.GetType() == typeof(char))
					retval = ((char)someValue) != (char)0;

				else if(someValue.GetType() == typeof(byte))
					retval = ((byte) someValue) != 0;

				else if(someValue.GetType()== typeof(short))
					retval = ((short)someValue) != 0;

				else if(someValue.GetType() == typeof(ushort))
					retval = ((ushort)someValue) != 0;

				else if (someValue.GetType() == typeof(long))
					retval = ((long)someValue) != 0;

				else if(someValue.GetType() == typeof(ulong))
					retval = ((ulong)someValue) != 0;

				else if(someValue.GetType() == typeof(float))
					retval = ((float)someValue) != 0;

				else if(someValue.GetType() == typeof(double))
					retval = ((double)someValue) != 0;

				else if(someValue.GetType() == typeof(decimal))
					retval = ((decimal)someValue) != 0;

				else if(someValue.GetType() == typeof(int))
					retval = ((int)someValue) != 0;
				
				else if(someValue.GetType() == typeof(string))
				{
					string stringValue = (string)someValue;
					if(stringValue.Length > 0)
						retval = true;
				}
			}

			return retval;
		}
	}
}
